package modelLag;
import java.util.ArrayList;

/**
 * Write a description of class CopyContainer here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class CopyContainer {
    // instance variables - replace the example below with your own
    private static CopyContainer cCon;
    private ArrayList<Copy> cList;

    /**
     * Constructor for objects of class CopyContainer
     */
    private CopyContainer() {
        // initialise instance variables
        cList = new ArrayList<Copy>();
    }

    /**
     * An example of a method - replace this comment with your own
     * 
     * @param  y   a sample parameter for a method
     * @return     the sum of x and y 
     */
    public static CopyContainer getInstance() {
        if(cCon ==null) {
            cCon = new CopyContainer();
        }
        return cCon;
    }
    
    public void addCopy(Copy copy) {
        cList.add(copy);
    }
    
    public Copy findCopy(int serialNumber) {
        int i=0;
        boolean found = false;
        Copy copy = null;
        while(i<cList.size() && !found) {
            Copy getCopy = cList.get(i);
            int copySerialNumber = getCopy.getSerial();
            if (copySerialNumber == (serialNumber)) {
                found = true;
                copy = cList.get(i);
                
            }
        }
        return copy;
    } 
    
    public void deleteCopy(int serialNumber) {
        int i = 0;
        boolean found = false;
        while(i<cList.size() && !found) {
            Copy getCopy = cList.get(i);
            int copySerialNumber = getCopy.getSerial();
            if (copySerialNumber == serialNumber) {
                found = true;
            }
            else {
            i++;
            }
        }
        if(found) {
            cList.remove(i);
        }
    }
}
